import React from 'react'
import {
    Form,
    Input,
    Button,
    Toast,
} from 'antd-mobile'
import request from '../../api/request'
import { useNavigate } from 'react-router-dom'
function Index() {
    const navigate = useNavigate();
    const onFinish =async (values) => {
        const res = await request.post('/api/login',values);
        console.log(res);
        if(res.code===200){
            localStorage.setItem('token',res.data.token);
            localStorage.setItem('userInfo',JSON.stringify(res.data.userInfo))
            Toast.show('登录成功')
            navigate('/index')
        }
    }
    return (
        <div>
            <Form
                name='form'
                onFinish={onFinish}
                footer={
                    <Button block type='submit' color='primary' size='large'>
                        登录
                    </Button>
                }
            >
                <Form.Header>演出登录</Form.Header>

                <Form.Item
                    name='username'
                    label='账号'
                    rules={[{ required: true, message: '账号不能为空' }]}
                >
                    <Input placeholder='请输入账号' />
                </Form.Item>


                <Form.Item
                    name='password'
                    label='密码'
                    rules={[{ required: true, message: '密码不能为空' }]}
                >
                    <Input placeholder='请输入密码' />
                </Form.Item>

            </Form>


        </div>
    )
}

export default Index
